/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.inter.rest;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.aop.annotation.BisLog;
import me.zhengjie.aop.service.BisLogService;
import me.zhengjie.business.domain.Sbgs;
import me.zhengjie.business.domain.Zhsq;
import me.zhengjie.business.domain.sup.Gsgl;
import me.zhengjie.business.domain.sup.Rygl;
import me.zhengjie.business.service.GsglService;
import me.zhengjie.business.service.RyglService;
import me.zhengjie.business.service.SbgsService;
import me.zhengjie.business.service.ZhsqService;
import me.zhengjie.business.service.dto.ZhsqQueryCriteria;
import me.zhengjie.inter.service.MpZhsqFhService;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* @website https://el-admin.vip
* @author xiahongbo
* @date 2022-04-15
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "居家照护申请复核")
@RequestMapping("/mp/zhsqfh")
public class MpZhsqFhController {

    private final ZhsqService zhsqService;
    private final MpZhsqFhService mpZhsqFhService;
    private final SbgsService sbgsService;

    private final RyglService ryglService;
    private final GsglService gsglService;

    @GetMapping(value = "/list")
    @ApiOperation("查询已评估的居家照护")
    public ResponseEntity<Object> queryAssess(ZhsqQueryCriteria criteria, Pageable pageable){
        Long userid = SecurityUtils.getCurrentUserId();
        Gsgl gsgl = gsglService.queryGsgl(userid);
        criteria.setBisSbgsId(gsgl.getBisGsglId());

        List<String> list = new ArrayList<>();
        list.add("04");
        criteria.setBisZhsqZt(list);
        return new ResponseEntity<>(PageUtil.toMpContent(zhsqService.queryAll(criteria,pageable)),HttpStatus.OK);
    }

    @PostMapping(value = "/checkZhsq")
    @Log("小程序复核居家照护申请")
    @ApiOperation("小程序复核居家照护申请")
    public ResponseEntity<Object> checkZhsq(@RequestBody Zhsq resources){
        mpZhsqFhService.updateZhzt(resources.getBisZhsqZt(), resources.getBisZhsqId(), resources.getBz());
        HashMap map = new HashMap<String,Object>();
        map.put("status","成功");
        return new ResponseEntity<>(PageUtil.toMpContent(map),HttpStatus.OK);
    }


    @PostMapping(value = "/checkFhjgzh")
    @Log("小程序复核机构照护申请")
    @ApiOperation("小程序复核机构照护申请")
    public ResponseEntity<Object> checkFhjgzh(@RequestBody Zhsq resources){
        mpZhsqFhService.checkFhjgzh(resources.getBisZhsqZt(), resources.getBisZhsqId(), resources.getBz());
        HashMap map = new HashMap<String,Object>();
        map.put("status","成功");
        return new ResponseEntity<>(PageUtil.toMpContent(map),HttpStatus.OK);
    }
}